package src.origintrail;

import java.util.ArrayList;

/**
 * A list class for every item in the game
 * @author csmythe
 */
public class ShopItemList {
    private ArrayList<ItemEntry> items;
    
    /**
     * Constructor
     */
    public ShopItemList(){
        items = new ArrayList<ItemEntry>();
        items.add(new ItemEntry("Clothing"));
        items.add(new ItemEntry("Food"));
        items.add(new ItemEntry("Oxen"));
        items.add(new ItemEntry("Wagon Repair Kit"));
    }
    
    /**
     * Getter of the whole array
     * @return this.items
     */
    public ArrayList<ItemEntry> getItems() {
        return items;
    }
    
    /**
     * Getter
     * @param i index
     * @return entry i's toString()
     */
    public String itemString(int i){
        return items.get(i).toString();
    }
    
    /**
     * Getter
     * @param i index
     * @return entry i's value
     */
    public double itemVal(int i){
        return items.get(i).getCost();
    }
    
    /**
     * Getter
     * @param i index
     * @return entry i's class
     */
    public String itemClass(int i){
        return items.get(i).getClassType();
    }
    
    /**
     * Getter
     * @param i index
     * @return entry i's mass
     */
    public double itemMass(int i){
        return items.get(i).getMass();
    }

    private static class ItemEntry {
        private final String name;
        private final String classType;
        private final double cost;
        private final double mass;

        public ItemEntry(String s) {
            this.name = s;
            this.classType = "src.origintrail." + s.replace(" ", "");
            double temp = 0;
            double temp2 = 0;
            try{
                Item i = ((Item)Class.forName(classType).newInstance());
                temp = i.initialize(1).getValue();
                temp2 = i.initialize(1).getWeight();
            }catch(Exception e){
                System.out.println("Class " + classType + " not found.");
            }
            cost = temp;
            mass = temp2;
        }
        
        public String toString(){
            return this.name;
        }
        
        public String getClassType(){
            return this.classType;
        }

        public double getCost() {
            return cost;
        }
        
        public String getName(){
            return name;
        }

        private double getMass() {
            return this.mass;
        }
    }
}
